package com.wj.facedetect.activity.alarm;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wj.facedetect.R;
import com.wj.facedetect.activity.base.BaseActivity;
import com.wj.facedetect.bean.alarm.TaskResultDetailBean;
import com.wj.facedetect.presenter.AlarmPresenter;
import com.wj.facedetect.util.ToastUtil;
import com.wj.facedetect.view.IBaseView;

import java.util.HashMap;

public class TaskResultDetailActivity extends BaseActivity implements IBaseView {
    private AlarmPresenter alarmPresenter;
    private TextView tvLeft;
    private SimpleDraweeView simpleDraweeView;
    private TextView tvDecs;
    private RelativeLayout rl;
    private String alarmId;
    private static final int REQ_TASK_RESULT = 0x001;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_result_detail);
        alarmPresenter = new AlarmPresenter(this);
        alarmId = getIntent().getStringExtra("warnId");
        initView();
        requestData();
    }

    private void initView() {
        tvLeft = (TextView) findViewById(R.id.tv_left);
        tvLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        simpleDraweeView = findViewById(R.id.iv_result);
        tvDecs = (TextView) findViewById(R.id.edit_bz);
        rl = (RelativeLayout) findViewById(R.id.rl_xczp);
    }

    public void requestData() {
        showProgressDialog();
        HashMap<String, String> params = new HashMap<>();
        params.put("warnId", alarmId);
        alarmPresenter.doRequestGetTaskResultDetail(params, REQ_TASK_RESULT, this);
    }

    @Override
    public void onSuccess(int what, Object data, Object carryObj) {
        dismissProgressDialog();
        if (what == REQ_TASK_RESULT) {
            TaskResultDetailBean taskResultDetailBean = (TaskResultDetailBean) data;
            if (taskResultDetailBean != null) {
                if (taskResultDetailBean.isSuccess()) {
                    TaskResultDetailBean.DataBean datax = taskResultDetailBean.getData();
                    if ("NORMAL".equals(datax.getStatus())) {
                        rl.setVisibility(View.VISIBLE);
                        simpleDraweeView.setImageURI(datax.getPic());

                    } else {
                        rl.setVisibility(View.GONE);
                    }
                    tvDecs.setText(datax.getDesc());
                }
            }
        }
    }

    @Override
    public void onError(int what, Exception e, Object carryObj) {
        dismissProgressDialog();
        ToastUtil.showMessage("网络异常");
    }

    @Override
    public void onFail(int what, int errorCode, String errorMsg, Object carryObj) {
        dismissProgressDialog();
    }
}
